package com.hzdesk.media.koreabatchmatvector.logic.view;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Chronometer;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.bean.MouseUserDevicesinfoBean;
import com.hzdesk.media.koreabatchmatvector.config.RxBusUtil;
import com.hzdesk.media.koreabatchmatvector.custom.SketchpadView;
import com.hzdesk.media.koreabatchmatvector.logic.contract.RecordScreenLabeledContract;
import com.hzdesk.media.koreabatchmatvector.logic.persenter.RecordScreenLabeledPersenter;
import com.hzdesk.media.koreabatchmatvector.utils.MyToastUtils;
import com.hzdesk.media.koreabatchmatvector.utils.SharedPreferencesUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/6/22.
 * 杭州席媒科技有限公司  Developers  刘传华  14
 * 佛祖镇楼 bug辟易
 */

public class RecordScreenLabeledActivity extends Activity implements RecordScreenLabeledContract.IRecordScreenLabeledView {
    private static final String TAG = RecordScreenLabeledActivity.class.getSimpleName();
    @BindView(R.id.activity_my_record_screen_lable_fl_surface_root)
    FrameLayout activityMyRecordScreenLableFlSurfaceRoot;

    @BindView(R.id.activity_my_record_screen_lable_tv_user)
    TextView activityMyRecordScreenLableTvUser;
    @BindView(R.id.activity_my_record_screen_lable_tv_user_cir)
    TextView activityMyRecordScreenLableTvUserCir;
    @BindView(R.id.activity_my_record_screen_lable_iv_rect)
    ImageView activityMyRecordScreenLableIvRect;
    @BindView(R.id.activity_my_record_screen_lable_ll_rect)
    LinearLayout activityMyRecordScreenLableLlRect;
    @BindView(R.id.main_imageview_oval)
    ImageView mainImageviewOval;
    @BindView(R.id.activity_my_record_screen_lable_ll_oval)
    LinearLayout activityMyRecordScreenLableLlOval;
    @BindView(R.id.activity_my_record_screen_lable_iv_line)
    ImageView activityMyRecordScreenLableIvLine;
    @BindView(R.id.activity_my_record_screen_lable_ll_line)
    LinearLayout activityMyRecordScreenLableLlLine;
    @BindView(R.id.activity_my_record_screen_lable_iv_paint)
    ImageView activityMyRecordScreenLableIvPaint;
    @BindView(R.id.activity_my_record_screen_lable_ll_paint)
    LinearLayout activityMyRecordScreenLableLlPaint;
    @BindView(R.id.activity_my_record_screen_lable_iv_strokes)
    ImageView activityMyRecordScreenLableIvStrokes;
    @BindView(R.id.activity_my_record_screen_lable_ll_strokes)
    LinearLayout activityMyRecordScreenLableLlStrokes;
    @BindView(R.id.activity_my_record_screen_lable_iv_color)
    ImageView activityMyRecordScreenLableIvColor;
    @BindView(R.id.activity_my_record_screen_lable_ll_color)
    LinearLayout activityMyRecordScreenLableLlColor;
    @BindView(R.id.activity_my_record_screen_lable_iv_undo)
    ImageView activityMyRecordScreenLableIvUndo;
    @BindView(R.id.activity_my_record_screen_lable_ll_undo)
    LinearLayout activityMyRecordScreenLableLlUndo;
    @BindView(R.id.activity_my_record_screen_lable_iv_redo)
    ImageView activityMyRecordScreenLableIvRedo;
    @BindView(R.id.activity_my_record_screen_lable_ll_redo)
    LinearLayout activityMyRecordScreenLableLlRedo;
    @BindView(R.id.activity_my_record_screen_lable_iv_clear)
    ImageView activityMyRecordScreenLableIvClear;
    @BindView(R.id.activity_my_record_screen_lable_ll_clear)
    LinearLayout activityMyRecordScreenLableLlClear;
    @BindView(R.id.activity_my_record_screen_lable_iv_play)
    ImageView activityMyRecordScreenLableIvPlay;
    @BindView(R.id.activity_my_record_screen_lable_ll_play)
    LinearLayout activityMyRecordScreenLableLlPlay;
    @BindView(R.id.activity_my_record_screen_lable_iv_file)
    ImageView activityMyRecordScreenLableIvFile;
    @BindView(R.id.activity_my_record_screen_lable_ll_file)
    LinearLayout activityMyRecordScreenLableLlFile;
    @BindView(R.id.activity_my_record_screen_lable_ll_menu_2)
    LinearLayout activityMyRecordScreenLableLlMenu2;
    @BindView(R.id.activity_my_record_screen_lable_ll_menu)
    LinearLayout activityMyRecordScreenLableLlMenu;
    @BindView(R.id.activity_my_record_screen_lable_sket)
    SketchpadView activityMyRecordScreenLableSket;
    @BindView(R.id.activity_my_record_screen_lable_image_record_point)
    ImageView activityMyRecordScreenLableImageRecordPoint;
    @BindView(R.id.activity_my_record_screen_lable_image_record_lin)
    LinearLayout activityMyRecordScreenLableImageRecordLin;
    @BindView(R.id.activity_my_record_screen_lable_rl_menu)
    RelativeLayout activityMyRecordScreenLableRlMenu;
    @BindView(R.id.activity_my_record_screen_lable_tv_record_chronmeter)
    Chronometer activityMyRecordScreenLableTvRecordChronmeter;
    @BindView(R.id.activity_my_record_screen_lable_image_record_mute)
    ImageView activityMyRecordScreenLableImageRecordMute;
    @BindView(R.id.activity_my_record_screen_lable_iv_set)
    ImageView activityMyRecordScreenLableIvSet;
    @BindView(R.id.activity_my_record_screen_lable_ll_set)
    LinearLayout activityMyRecordScreenLableLlSet;
    @BindView(R.id.activity_my_record_screen_lable_ll_menu_left)
    LinearLayout activityMyRecordScreenLableLlMenuLeft;


    private RecordScreenLabeledPersenter mRecordScreenLabeledPersenter = new RecordScreenLabeledPersenter(this);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_record_screen_lable);
        ButterKnife.bind(this);
        mRecordScreenLabeledPersenter.initView(this, activityMyRecordScreenLableSket);
        mRecordScreenLabeledPersenter.setOnMenuShowListener(activityMyRecordScreenLableRlMenu);
        mRecordScreenLabeledPersenter.setOnMenuHideListener(activityMyRecordScreenLableLlMenu);
        mRecordScreenLabeledPersenter.bindRecordScreenService(activityMyRecordScreenLableFlSurfaceRoot, this);
    }

    @OnClick({R.id.activity_my_record_screen_lable_ll_set,R.id.activity_my_record_screen_lable_tv_user,
            R.id.activity_my_record_screen_lable_ll_rect,
            R.id.activity_my_record_screen_lable_ll_oval, R.id.activity_my_record_screen_lable_ll_line,
            R.id.activity_my_record_screen_lable_ll_paint, R.id.activity_my_record_screen_lable_ll_strokes,
            R.id.activity_my_record_screen_lable_ll_color, R.id.activity_my_record_screen_lable_ll_undo,
            R.id.activity_my_record_screen_lable_ll_redo, R.id.activity_my_record_screen_lable_ll_clear,
            R.id.activity_my_record_screen_lable_ll_play, R.id.activity_my_record_screen_lable_ll_file
    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_my_record_screen_lable_tv_user:                                      //Loading
                break;
            case R.id.activity_my_record_screen_lable_ll_rect:                                      //底部栏 框
                mRecordScreenLabeledPersenter.setStrokeType(SketchpadView.STROKE_RECT);
                break;
            case R.id.activity_my_record_screen_lable_ll_oval:                                      //底部栏 橡皮檫(椭圆)
                mRecordScreenLabeledPersenter.setStrokeType(SketchpadView.STROKE_OVAL);
                break;
            case R.id.activity_my_record_screen_lable_ll_line:                                      //底部栏 直线
                mRecordScreenLabeledPersenter.setStrokeType(SketchpadView.STROKE_LINE);
                break;
            case R.id.activity_my_record_screen_lable_ll_paint:                                     //底部栏 自由曲线
                mRecordScreenLabeledPersenter.setStrokeType(SketchpadView.STROKE_PEN);
                break;
            case R.id.activity_my_record_screen_lable_ll_strokes:                                   //底部栏 笔触
                mRecordScreenLabeledPersenter.changeStroke(activityMyRecordScreenLableLlStrokes);
                break;
            case R.id.activity_my_record_screen_lable_ll_color:                                     //底部栏 颜色
                mRecordScreenLabeledPersenter.changeStrokeColor(activityMyRecordScreenLableLlColor);
                break;
            case R.id.activity_my_record_screen_lable_ll_undo:                                      //底部栏 上一步
                mRecordScreenLabeledPersenter.undo();
                break;
            case R.id.activity_my_record_screen_lable_ll_redo:                                      //底部栏 下一步
                mRecordScreenLabeledPersenter.redo();
                break;
            case R.id.activity_my_record_screen_lable_ll_clear:                                     //底部栏 清除
                mRecordScreenLabeledPersenter.clearAllStrokes(1);
                break;
            case R.id.activity_my_record_screen_lable_ll_play:                                      //底部栏 录屏
                mRecordScreenLabeledPersenter.onClickedPlayer(this);
                break;
            case R.id.activity_my_record_screen_lable_ll_file:                                      //底部栏 文件
                mRecordScreenLabeledPersenter.onclickedFile();
                break;
            case R.id.activity_my_record_screen_lable_ll_set:
                mRecordScreenLabeledPersenter.onclickeSetting();
                break;
        }
    }

    @Override
    public void showMesssage(String msg) {
        MyToastUtils.ShortToaseShow(this, msg);
    }

    @Override
    public void toDialogPager() {
        Intent intent = new Intent(RecordScreenLabeledActivity.this, TimeLineActivity.class);
        startActivity(intent);
    }

    @Override
    public void toSettingPager() {
        Intent intent = new Intent(RecordScreenLabeledActivity.this, SystemSettingsActivity.class);
        startActivity(intent);
    }

    @Override
    public void tofinshPager() {
        startActivity(new Intent(RecordScreenLabeledActivity.this, MainActivity.class));
        finish();
    }

    @Override
    public void showUser(MouseUserDevicesinfoBean bean) {
        activityMyRecordScreenLableTvUser.setText(getResources().getString(R.string.currentUser) + bean.getName());
        activityMyRecordScreenLableTvUserCir.setTextColor(Color.parseColor("#" + bean.getColor()));
        //activityMyRecordScreenLableIvUser.setImageBitmap(bitmapList.get(bean.getColorindex()));
    }

    @Override
    public void onstartRecord() {
        activityMyRecordScreenLableImageRecordLin.setVisibility(View.VISIBLE);
        activityMyRecordScreenLableTvRecordChronmeter.setBase(SystemClock.elapsedRealtime());
        activityMyRecordScreenLableTvRecordChronmeter.start();
        if (SharedPreferencesUtils.getRecordMode(this) == 1) {
            activityMyRecordScreenLableImageRecordMute.setVisibility(View.GONE);
        }

    }

    @Override
    public void onstopRecrd() {
        activityMyRecordScreenLableImageRecordLin.setVisibility(View.GONE);
        activityMyRecordScreenLableTvRecordChronmeter.stop();

    }

    @Override
    public void onshowMenu() {
        activityMyRecordScreenLableLlMenu.setVisibility(View.VISIBLE);
        activityMyRecordScreenLableRlMenu.setVisibility(View.GONE);

    }

    @Override
    public void onhideMenu() {
        activityMyRecordScreenLableLlMenu.setVisibility(View.GONE);
        activityMyRecordScreenLableRlMenu.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.e(TAG, "onResume========================");

    }

    @Override
    protected void onPause() {
        super.onPause();
        mRecordScreenLabeledPersenter.unbindRecordScreenService(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mRecordScreenLabeledPersenter.onActivityResult(requestCode, resultCode, data);
    }

}
